package cn.fengtang.chatglm.data.config;

import cn.fengtang.chatglm.session.OpenAiSessionFactory;
import cn.fengtang.chatglm.session.defaults.DefaultOpenAiSessionFactory;
import okhttp3.logging.HttpLoggingInterceptor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import cn.fengtang.chatglm.session.OpenAiSession;

@Configuration
@EnableConfigurationProperties(ChatGLMSDKConfigProperties.class)
public class ChatGLMSDKConfig {

    @Bean
    public OpenAiSession openAiSession(ChatGLMSDKConfigProperties properties) {
        cn.fengtang.chatglm.session.Configuration configuration = new cn.fengtang.chatglm.session.Configuration();

        configuration.setApiHost(properties.getApiHost());
        configuration.setApiSecretKey(properties.getApiKey());
        configuration.setLevel(HttpLoggingInterceptor.Level.BODY);
        //2.会话工厂
        OpenAiSessionFactory factory = new DefaultOpenAiSessionFactory(configuration);
        //3.开启会话
        return factory.openSession();
    }
}
